package com.golden.order02.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.golden.order02.dao.OrderSessionMapper;
import com.golden.order02.domain.OrderSessionDO;
import com.golden.order02.domain.ResultDO;
import com.golden.order02.entity.OrderSession;
import com.golden.order02.query.OrderSessionExample;

@Service
public class OrderSessionServiceImpl implements OrderSessionService{
	
	@Autowired
	OrderSessionMapper orderSessionMapper;
	
	public ResultDO<OrderSessionDO> get( Integer id){
		
		ResultDO<OrderSessionDO> result=new ResultDO<OrderSessionDO>();
		BaseServiceImpl<OrderSessionDO,OrderSession> bi=new BaseServiceImpl<>();
		OrderSessionDO oo=new OrderSessionDO();
		
		try {
			OrderSession selectByPrimaryKey = orderSessionMapper.selectByPrimaryKey(id);
			OrderSessionDO t = bi.getT(selectByPrimaryKey, oo);
			result.setData(t);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_QUERY_ERROR);
			result.setErrorMsg(ResultDO.ORDER_QUERY_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<List<OrderSessionDO>> query( OrderSessionExample example){
		ResultDO<List<OrderSessionDO>> result=new ResultDO<List<OrderSessionDO>>();
		BaseServiceImpl<OrderSessionDO,OrderSession> bi=new BaseServiceImpl<>();
		OrderSessionDO oo=new OrderSessionDO();
		try {
			List<OrderSession> selectByExample = orderSessionMapper.selectByExample(example);
			List<OrderSessionDO> tList = bi.getTList(selectByExample, oo);
			result.setData(tList);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_QUERY_ERROR);
			result.setErrorMsg(ResultDO.ORDER_QUERY_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<OrderSessionDO> add( OrderSessionDO beanDO){
		ResultDO<OrderSessionDO> result=new ResultDO<OrderSessionDO>();
		BaseServiceImpl<OrderSession, OrderSessionDO> bi=new BaseServiceImpl<>();
		OrderSession oi=new OrderSession();
		OrderSession t = bi.getT(beanDO, oi);
		try {
			int insert = orderSessionMapper.insert(t);
			if(insert<=0) {
				throw new Exception();
			}
			beanDO.setId(t.getId());
			result.setData(beanDO);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_ADD_ERROR);
			result.setErrorMsg(ResultDO.ORDER_ADD_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<Integer> delete( Integer id){
		ResultDO<Integer> result=new ResultDO<Integer>();
		try {
			int deleteByPrimaryKey = orderSessionMapper.deleteByPrimaryKey(id);
			if(deleteByPrimaryKey<=0) {
				throw new Exception();
			}
			result.setData(id);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_DELETE_ERROR);
			result.setErrorMsg(ResultDO.ORDER_DELETE_MSG_ERROR);
		}
		return result;
	}
	
	public ResultDO<OrderSessionDO> modify( OrderSessionDO beanDO){
		ResultDO<OrderSessionDO> result=new ResultDO<OrderSessionDO>();
		BaseServiceImpl<OrderSession, OrderSessionDO> bi=new BaseServiceImpl<>();
		OrderSession oi=new OrderSession();
		OrderSession t = bi.getT(beanDO, oi);
		try {
			int insert = orderSessionMapper.updateByPrimaryKeySelective(t);
			if(insert<=0) {
				throw new Exception();
			}
			result.setData(beanDO);
		} catch (Exception e) {
			result.setSuccess(false);
			result.setErrorCode(ResultDO.ORDER_MODIFY_ERROR);
			result.setErrorMsg(ResultDO.ORDER_MODIFY_MSG_ERROR);
		}
		return result;
	}
	
	
}
